﻿using NetFrame.Model;
using NetFrame.Persistance;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace NetFrame.UI
{
    public partial class JobEdit : Form
    {
        private Job _job=new Job();
        public JobEdit(Job job)
        {
            _job = job;
            InitializeComponent();
            DataBind();
            
        }

        private void DataBind()
        {
            rowstatusCombo.DataSource = new List<int>() { 0, 1, 2 };
            idText.DataBindings.Add("Text", _job, "Id");
            jobNameText.DataBindings.Add("Text", _job, "JobName");
            trigerText.DataBindings.Add("Text", _job, "Triger");
            regCronText.DataBindings.Add("Text", _job, "RegCron");
            remarkText.DataBindings.Add("Text", _job, "Remark");
            scriptRichText.DataBindings.Add("Text", _job, "Script");
            rowstatusCombo.DataBindings.Add("Text", _job, "RowStatus");
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_job.Triger) || string.IsNullOrWhiteSpace(_job.JobName) || string.IsNullOrWhiteSpace(_job.Remark))
            {
                MessageBox.Show("请相关参数填写完整");
                return;
            }
            BasePersistance<Job>.DoAction((t) => t.Adapter.CreateUpdate(_job));
            this.Close();
        }
    }
}
